//
//  AssociationKey.swift
//  HZJTreeView
//
//  Created by 何治军 on 2020/6/18.
//  Copyright © 2020 何治军. All rights reserved.
//

/// 在扩展中添加属性用的
struct AssociationKey {
    static var keysDic:[String: UnsafeRawPointer] = [:]
    static func from(_ str:String) -> UnsafeRawPointer{
        if let key = keysDic[str] {
            return key
        }else{
            let bufferkey = str.data(using: .utf8)?.withUnsafeBytes({ (uint8Ptr) -> UnsafeRawBufferPointer in
                return UnsafeRawBufferPointer(uint8Ptr)
            })
            if let pointer = bufferkey?.baseAddress {
                keysDic[str] = pointer
                return pointer
            }
            return UnsafeRawPointer(from("underfind"))
        }
    }
}
